var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');



var app = getApp();

Page({
  data: {
    goodsId:0,
    assessList:[],
    rec_id:0,
    starList:[{id:1},{id:2},{id:3},{id:4},{id:5}]    
  },
  formSubmit:function(e){
    var that = this;
    let user_id = wx.getStorageSync('userId');
    let goods_id=that.data.goodsId;
    let rec_id=that.data.rec_id;
    let starList = that.data.starList;
    let starnum=0;
    let msg_content = e.detail.value.msg_content;
    for (var index in starList) {
        if (starList[index].checked) {
          starnum+=1;
        }
    }
    let mdata = { user_id: user_id, goods_id: goods_id, rec_id: rec_id, star: starnum, msg_content: msg_content};
    util.request(api.assessAdd, mdata).then(function (res) {
      if (res.errno == 0) {
        wx.showToast({
          title: res.data,
          icon: 'success',
          duration: 2000
        })
        wx.redirectTo({
          url: '/pages/ucenter/index/index',
        })
      }
    });
  },
  onLoad: function (options) {
    let goods_id = options.id;
    let rec_id=options.rec_id;
    if (typeof goods_id != "undefined") {
      this.setData({
        goodsId: goods_id,
        rec_id: rec_id
      });
    }
    this.getAssessList();
  },
  getAssessList() {
    let that = this;
    let user_id = wx.getStorageSync('userId');
    let userdata = { goods_id: that.data.goodsId};
    util.request(api.assessAddPage, userdata).then(function (res) {
      if (res.errno == 0) {
        that.setData({
          assessList: res.data,
        })
      }
    });
  },
  starchange:function(event){
    let that=this;
    let id=event.target.dataset.indexId;
    let starList=that.data.starList;
    for (var index in starList) {
      if(starList[index].id==id){
        if(starList[index].checked){
          starList[index].checked=false;
        }else{
          starList[index].checked = true;
        }
      }
    }
    that.setData({
      starList: starList
    })
  },
  onReady: function () {
    

  },
  onShow: function () {

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭
  }
})